package com.ruoyi.psi.base.category.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.psi.base.category.domain.BaseCategory;
import com.ruoyi.psi.base.category.service.IBaseCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品类别信息
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/psi/base/category")
@Api(value = "产品类别信息模块", tags = "产品类别接口")
public class BaseCategoryController extends BaseController {

    @Autowired
    private IBaseCategoryService baseCategoryService;

    /**
     * 获取产品类别列表
     * 需前端处理形成树形结构
     * @param baseCategory
     * @return
     */
    @ApiOperationSupport(includeParameters = {"BaseCategory.baseCategoryId", "BaseCategory.baseCategoryName"})
    @ApiOperation(value = "获取产品类别列表",notes = "查询所有产品类别信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody BaseCategory baseCategory) {
        startPage();
        List<BaseCategory> baseCategoryList = baseCategoryService.selectBaseCategoryList(baseCategory);
        return getDataTable(baseCategoryList);
    }

    /**
     * 导出产品类别
     *
     * @param baseCategory
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody BaseCategory baseCategory) {
        List<BaseCategory> list = baseCategoryService.selectBaseCategoryList(baseCategory);
        ExcelUtil<BaseCategory> util = new ExcelUtil<BaseCategory>(BaseCategory.class);
        return util.exportExcel(list, "产品类别数据");
    }

    /**
     * 新增产品类别
     *
     * @param baseCategory
     * @return
     */
    @ApiOperation(value = "新增产品类别", notes = "新增产品类别")
    @ApiImplicitParam(name = "baseCategory", value = "新增产品类别", dataType = "BaseCategory")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody BaseCategory baseCategory) {

        return toAjax(baseCategoryService.insertBaseCategory(baseCategory));
    }

    /**
     * 修改产品类别
     *
     * @param baseCategory
     * @return
     */
    @ApiOperation(value = "修改产品类别", notes = "修改产品类别")
    @ApiImplicitParam(name = "baseCategory", value = "新增产品类别", dataType = "BaseCategory")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody BaseCategory baseCategory) {
        return toAjax(baseCategoryService.updateBaseCategory(baseCategory));
    }

    /**
     * 删除产品类别
     * 仅修改删除标志位
     *
     * @param baseCategory
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody BaseCategory baseCategory) {
        return toAjax(baseCategoryService.updateBaseCategoryDeleteFlag(baseCategory));
    }
}
